package com.free.space.common;

import org.springframework.stereotype.Controller;

import java.io.File;

/**
 * 文件摘要比对
 * Created by zhulj on 2019/3/25.
 */
@Controller
public class FileCompareController {
    /**
     * 读取文件
     * 递归扫描子目录
     * 读取文件内容，调用摘要算法
     * @param filepath
     */
    public static void readfile(String filepath) {
        try {
            File file = new File(filepath);
            if (!file.isDirectory()) {
                MD5DigestTool.md5DigestCompute(file);
            } else if (file.isDirectory()) {
                System.out.println("文件夹");
                String[] filelist = file.list();
                for (int i = 0; i < filelist.length; i++) {
                    File readfile = new File(filepath + "\\" + filelist[i]);
                    if (!readfile.isDirectory()) {
                        MD5DigestTool.md5DigestCompute(readfile);
                    } else if (readfile.isDirectory()) {
                        readfile(filepath + "\\" + filelist[i]);
                    }
                }
            }
        } catch (Exception e) {
            System.out.println("readfile()   Exception:" + e.getMessage());
        }
    }

    public static void main(String[] args) {
        String filepath = "E:\\医院产品包制作\\V3.0\\product-v3.1.0\\MedicationKnowledge\\drugmanualhtml";
        readfile(filepath);
    }

}
